package com.artpri.action.user;

import java.util.List;

import com.artpri.action.BaseAction;
import com.artpri.model.ShopCart;
import com.artpri.model.vo.ShopCartVo;
import com.artpri.model.vo.SimpleGoods;

/**
 * 购物车
 * @author ZhangSi
 */
public class ShoppingCartAction extends BaseAction{

	private static final long serialVersionUID = -5159283217031078546L;

	private List<Integer> goodsNum; // 商品编号

	private List<Integer> buyNum;  // 购买数量

	private String msg;  // 添加结果

	private List<Integer> cartIds; // ids 批量删除
	
	private Integer id;

	private String delType;
	
	private List<ShopCartVo> shopCarts; // 购物车列表

	private ShopCart shopCart; // 购物车

	private List<SimpleGoods> goodsList;
	
	/**
	 *	添加购物车 
	 */
	public String addCart() throws Exception {
		int userNum = getSessionUser().getUserNum();
		getShoppingCartService().addCarts(goodsNum, buyNum, userNum);
		goodsList = getShoppingCartService().getSimpleGoods(goodsNum);
		return SUCCESS;
	}
	
	/**
	 *	删除购物车 
	 */
	public String deleteCart() throws Exception {
		//getShoppingCartService().deleteCart(cartIds);
		
		if (delType.equals("one")) {
			getShoppingCartService().deleteCart(id);
		} else if (delType.equals("all")) {
			getShoppingCartService().deleteCart(cartIds);
		}
		msg = "success";
		return SUCCESS;
	}

	/**
	 *	购物车列表 
	 */
	public String listCart() throws Exception {
		shopCarts = getShoppingCartService().getShopCartByUser(getSessionUser().getUserNum());
		return SUCCESS;
	}
	
	/**
	 *	更新购物车 
	 */
	public String updateCart() throws Exception {
		
		getShoppingCartService().updateCart(shopCart);
		
		return SUCCESS;
	}
	
	/**
	 *	清除下柜商品 
	 */
	public String removeStopSellingGoods() throws Exception {
		cartIds = getShoppingCartService().removeStopSellingGoods(cartIds);
		return SUCCESS;
	}
	
	public List<Integer> getGoodsNum() {
		return goodsNum;
	}

	public void setGoodsNum(List<Integer> goodsNum) {
		this.goodsNum = goodsNum;
	}

	public List<Integer> getBuyNum() {
		return buyNum;
	}

	public void setBuyNum(List<Integer> buyNum) {
		this.buyNum = buyNum;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public List<Integer> getCartIds() {
		return cartIds;
	}

	public void setCartIds(List<Integer> cartIds) {
		this.cartIds = cartIds;
	}

	public List<ShopCartVo> getShopCarts() {
		return shopCarts;
	}

	public void setShopCarts(List<ShopCartVo> shopCarts) {
		this.shopCarts = shopCarts;
	}

	public ShopCart getShopCart() {
		return shopCart;
	}

	public void setShopCart(ShopCart shopCart) {
		this.shopCart = shopCart;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getDelType() {
		return delType;
	}

	public void setDelType(String delType) {
		this.delType = delType;
	}

	public List<SimpleGoods> getGoodsList() {
		return goodsList;
	}

	public void setGoodsList(List<SimpleGoods> goodsList) {
		this.goodsList = goodsList;
	}
}
